<template>
    <div class="puto">
        <!--添加按钮-->
        <div>

            <!-- 添加按钮 -->
            <el-button type="primary" @click="addGoods">添加</el-button>
            <el-select v-model="cle1" placeholder="请选择" @change="asdf($evle)">
                <el-option
                        v-for="item in user1"
                        :key="item.cid"
                        :label="item.name"
                        :value="item.name">
                </el-option>
            </el-select>
            <el-select v-model="cle2" placeholder="请选择" @change="asert($evle)">
                <el-option
                        v-for="item in user2"
                        :key="item.cid"
                        :label="item.name"
                        :value="item.name">
                </el-option>
            </el-select>
            <el-select v-model="cle3" placeholder="请选择">
                <el-option
                        v-for="item in user3"
                        :key="item.cid"
                        :label="item.name"
                        :value="item.name">
                </el-option>
            </el-select>
            <!-- 添加对话框 -->
            <el-dialog :visible.sync="addGoodsDialogVisible" title="添加物资">
                <el-form :model="addGoodsForm" label-width="100px">
                    <el-form-item label="物资名称">
                        <el-select v-model="addGoodsForm.goodsName" placeholder="请选择">
                            <el-option v-for="item in goodsOptions" :key="item.Id" :label="item.Goods_name" :value="item.Id"></el-option>
                        </el-select>

                    </el-form-item>
                    <el-form-item label="物资申请数量">
                        <el-input-number v-model="addGoodsForm.goodsAmount" :min="1" :precision="0"></el-input-number>
                    </el-form-item>


                </el-form>
                <div slot="footer" class="dialog-footer">
                    <el-button @click="addGoodsDialogVisible = false">取消</el-button>
                    <el-button type="primary" @click="addGoodsSubmit">确定</el-button>
                </div>
            </el-dialog>
        </div>
        <!--表格-->
        <el-table :data="stuce" style="width: 100%">
            <el-table-column prop="goodsName" label="物资名称"></el-table-column>
            <el-table-column prop="goodsAmount" label="物资申请数量"></el-table-column>
            <el-table-column prop="goodsId" label="物资编号"></el-table-column>
            <el-table-column prop="goodsApplicantId" label="物资申请人id"></el-table-column>
            <el-table-column prop="goodsApplicantName" label="物资申请人名字"></el-table-column>
            <el-table-column prop="examineStatus" label="申请状态" :formatter="formatStatus">
                <template slot-scope="scope">{{ scope.row.examineStatus==1?"等待审批":scope.row.examineStatus==2?"审批通过":"审批拒绝" }}</template>
            </el-table-column>
            <el-table-column prop="examineReason" label="审批结果"></el-table-column>
        </el-table>
    </div>
</template>

<script>
    export default {
        name: "Puto",
        data(){
            return{
                cle1:"",
                cle2:"",
                cle3:"",
                ffff:{
                  ss:"",
                },
                user1:[],
                user2:[],
                user3:[],
                addGoodsDialogVisible: false, // 添加物资对话框是否可见
                addGoodsForm: { // 添加物资表单数据
                    goodsName: '',
                    goodsAmount: 0,
                    goodsId: '',
                    goodsApplicantId:"",
                    goodsApplicantName:"",
                },
                id:"",
                name:"",
                stuce:[],
                goodsData: [
                    // 这些是给大家模拟的假数据，请你在fetchGoodsOptions方法进行异步查询，下面假数据你看懂意思后，请删除掉，不要用假数据来迷惑老师
                    {
                        Id: '1',
                        Goods_name: '物资1',
                        Goods_amount: 10,
                        Goods_id: '10001',
                        Goods_applicant_id: '001',
                        Goods_applicant_name: '张三',
                        Examine_status: 1,
                        Examine_reason: ''
                    },
                    {
                        Id: '2',
                        Goods_name: '物资2',
                        Goods_amount: 20,
                        Goods_id: '10002',
                        Goods_applicant_id: '002',
                        Goods_applicant_name: '李四',
                        Examine_status: 2,
                        Examine_reason: ''
                    },
                    {
                        Id: '3',
                        Goods_name: '物资3',
                        Goods_amount: 30,
                        Goods_id: '10003',
                        Goods_applicant_id: '003',
                        Goods_applicant_name: '王五',
                        Examine_status: 3,
                        Examine_reason: '数量超过库存'
                    }
                ],
                goodsOptions: [
                    {
                        Id: '雨伞',
                        Goods_name: '雨伞'
                    },
                    {
                        Id: '口罩',
                        Goods_name: '口罩'
                    }
                ] // 物资下拉框选项
            }
        },
        methods:{

            initSche(){
                this.cle1="";
                this.cle2="";
                this.cle3="";
                this.axios.post(`http://localhost:82/heash/findAll?cid=`).then(res=>{
                    this.user1=res.data;
                });
                this.ffff.ss=this.cle1+"-"+this.cle2+"-"+this.cle3;

            },
            asdf(elve){
                this.cle2="";
                this.cle3="";
                this.axios.post(`http://localhost:82/heash/findAlls?name=${this.cle1}`).then(res=>{
                    this.user2=res.data;
                });
                this.ffff.ss=this.cle1+"-"+this.cle2+"-"+this.cle3;

            },
            asert(elve){
             this.cle3="";
                this.axios.post(`http://localhost:82/heash/findAlls?name=${this.cle2}`).then(res=>{
                    this.user3=res.data;
                });
                this.ffff.ss=this.cle1+"-"+this.cle2+"-"+this.cle3;

            },
            initData(){
                this.axios.post(`http://localhost:82/stuce/findAll`).then(res=>{
                    this.stuce=res.data;
                });

            },
            addGoodsSubmit(){

                this.addGoodsForm.goodsId=1000+this.$route.query.id;
                this.addGoodsForm.goodsApplicantId=this.$route.query.id;
                this.addGoodsForm.goodsApplicantName=this.$route.query.username;
                this.axios.post(`http://localhost:82/stuce/add`,this.addGoodsForm).then(res=>{
                    if (res.data.code==0){
                        this.initData();
                        this.addGoodsDialogVisible=false;
                        this.$message.success("添加成功");
                    }
                })
            },
            //格式化申请状态
            formatStatus(row) {
                if (row.Examine_status === 1) {
                    return '等待审批';
                } else if (row.Examine_status === 2) {
                    return '审批通过';
                } else if (row
                    .Examine_status === 3) {
                    return '审批拒绝';
                } else {
                    return '';
                }
            },
            // 添加物资按钮点击事件
            addGoods() {
                // 显示添加物资对话框
                this.addGoodsDialogVisible = true;
            }
        },
        created(){
this.initData();
this.id=this.$route.query.id;
this.name=this.$route.query.username;
this.initSche();
        }
    }
</script>

<style scoped>

</style>